//统一管理咱们项目用户相关的接口
import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import qs from 'qs'
import {
  MenuInfoPageParams,
  MenuInfoParams,
  MenuInfoRes,
  MenuPageRes,
  RoutesRes,
} from './type'
// 项目用户相关的请求地址

enum Menus_API {
  GET_MENU_PAGE = '/teaching_system/menu/more',
  POST_PUT_MENU_INFO = '/teaching_system/menu/one',
  GET_DELETE_MENI_BYID = '/teaching_system/menu/one/{id}',
  GET_MENU_OPTIONS = '/teaching_system/menu/option',
  GET_MENU_ROUTES_BYROLEID = '/teaching_system/menu/routes/{roleId}',
  GET_MENU_OPTIONS_BYID = '/teaching_system/menu/option/{roleId}',
}

//获取菜单分页
export const reqGetMenuPage = (params: MenuInfoPageParams) =>
  request.get<any, AxiosResponse<MenuPageRes>>(
    Menus_API.GET_MENU_PAGE + '?' + qs.stringify(params),
  )

export const reqAddMenu = (data: MenuInfoParams) =>
  request.post<any, AxiosResponse<any>>(Menus_API.POST_PUT_MENU_INFO, data)

export const reqChangeMenu = (data: MenuInfoParams) =>
  request.put<any, AxiosResponse<any>>(Menus_API.POST_PUT_MENU_INFO, data)

export const reqGetMenuById = (id: number) =>
  request.get<any, AxiosResponse<MenuInfoRes>>(
    Menus_API.GET_DELETE_MENI_BYID.replace('{id}', id.toString()),
  )

export const reqDeleteMenuById = (id: number) =>
  request.delete<any, AxiosResponse<MenuInfoRes>>(
    Menus_API.GET_DELETE_MENI_BYID.replace('{id}', id.toString()),
  )

export const reqGetMenuOption = () =>
  request.get<any, AxiosResponse<MenuInfoRes[]>>(Menus_API.GET_MENU_OPTIONS)

export const reqGetRoutesByRoleId = (roleId: number) =>
  request.get<any, AxiosResponse<RoutesRes[]>>(
    Menus_API.GET_MENU_ROUTES_BYROLEID.replace('{roleId}', roleId.toString()),
  )

export const reqGetMenuOptionsById = (roleId: number) =>
  request.get<any, AxiosResponse<number[]>>(
    Menus_API.GET_MENU_OPTIONS_BYID.replace('{roleId}', roleId.toString()),
  )
